<template>
  <div class="about">
    <h1>This is an about page</h1>
    <md-button type="primary" @click="naviInit">naviInit</md-button>
    <md-button type="primary" @click="back">back</md-button>
    <md-button type="primary" @click="popView">popView</md-button>
    <md-button type="primary" @click="wxPayment">wxPayment</md-button>
    <md-button type="primary" @click="Alipay">Alipay</md-button>
  </div>
</template>
<script>
  import {
    Button,
    Toast,
    Dialog
  } from 'mand-mobile'
  import wx from '@/utils/weixin'
  export default {
    data() {
      return {

      }
    },
    components: {
      'md-button': Button
    },
    created() {
      this.naviInit()
      Dialog.alert({
        title: '测试',
        content: this.$store.getters.getToken,
        cancelText: '取消',
        confirmText: '确定',
        onConfirm: () => console.log('[Dialog.alert] confirm clicked'),
      })
      wx.share({
        title: '微信分享测试',
        desc: '微信分享测试balabala',
        link: window.location.href,
        imgUrl: '@/assets/logo.png',
      })
    },
    methods: {
      popView() {
        Toast.info('开始调用popView')
        this.$app.popView().then(res => {
          Toast.info(res)
        })
      },
      back() {
        Toast.info('开始调用back')
        this.$app.back().then(res => {
          Toast.info(res)
        })
      },
      naviInit() {
        Toast.info('设置标题')
        let _this = this
        let params = {
          setTitle: {
            title: '瑞仟基金'
          },
          setButton: {
            buttonArrary: [{
                jsFunction: this.share,
                text: '分享'
              },
              {
                jsFunction: this.butFunc2,
                text: '自定义按钮二'
              }, {
                jsFunction: this.butFunc3,
                text: '自定义按钮二'
              }
            ]
          }
        }
        Toast.info('开始调用naviInit')
        this.$app.naviInit(params).then(function (res) {
          _this.buttonCallBack = window.$appBridge.naviInit.buttonCallBack
          Toast.info(res)
        }, function () {
          console.log('调用失败')

        })
      },
      butFunc1() {
        Toast.info('按钮1')
        console.log('按钮1')
      },
      butFunc2() {
        Toast.info('按钮2')
        console.log('按钮2')
      },
      butFunc3() {
        Toast.info('按钮3')
        console.log('按钮3')
      },
      share() {
        Toast.info('开始调用share')
        let params = {
          shareChannel: [{
            type: this.$app.SHARE_TYPE_ENUM.WX_FRIEND,
            shareType: 1,
            text: 'app分享测试'
          }]
        }
        this.$app.share(params)
      },
      wxPayment() {
        let _this = this
        _this.$app.wxPayment({
          businessData: {
            appid: 'wxd5f2bab055d6d371',
            partnerid: '2019081400001',
            prepayid: '657544368896',
            noncestr: 'wx3143fder2dfswe2',
            sign: 'wx434f34edg34rrgg'
          }
        }).then(res => {
          Toast.info(res)
        })
      },
      Alipay() {
        let _this = this
        _this.$app.Alipay({
          businessData: {
            orderStr: '201908140000001'
          }
        }).then(res => {
          Toast.info(res)
        })
      }
    }
  }
</script>